<html>
<head><meta charset="utf-8"><title>text-size · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html">text-size</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="189183148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/189183148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#189183148">(Feb 27 2020 at 03:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/rowan-next.20(bonsai)/near/189099214" title="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/rowan-next.20(bonsai)/near/189099214">said</a>:</p>
<blockquote>
<p>Ok, let's start small :)</p>
<p>I want to commit to having 1.0 version of text-unit/str-index/text-size crate in three months. To that end:</p>
<ul>
<li>I propose spending some time for the final bikeshed. I like <code>TextSize</code> color the most :P</li>
<li>After we bikeshed, we release the 0.99 version of this library, even if there are bits I don't like/am not sure about.</li>
<li>We migrate rowan and rust-analyzer to 0.99</li>
<li>After a month, unless something truly outrageous comes up, we bump version to 1.0 (with maybe even a semver trick to make migration trully flawless).</li>
</ul>
</blockquote>
<p>I'm going to drop impl notes here as I try to find a nice balance between text_unit and str-index.</p>



<a name="189183200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/189183200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#189183200">(Feb 27 2020 at 03:04)</a>:</h4>
<p><code>TextSize</code> is nice, but falls short on one important note: constructing <code>TextRange</code></p>



<a name="189183226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/189183226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#189183226">(Feb 27 2020 at 03:05)</a>:</h4>
<p>Because <code>TextSize</code> is the "size" of a string it feels kind of weird to use as also an index</p>



<a name="189183275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/189183275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#189183275">(Feb 27 2020 at 03:06)</a>:</h4>
<p>Though I suppose that's a flown ship (wait wut) given Rust uses <code>usize</code> for both "size" (of an array) and "index"</p>



<a name="189194417"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/189194417" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#189194417">(Feb 27 2020 at 08:23)</a>:</h4>
<p>Yeah, exactly: <code>xs[..92]</code> is a range with size as a bound</p>



<a name="189194474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/189194474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#189194474">(Feb 27 2020 at 08:24)</a>:</h4>
<p>(index is also weird in a sense that it's impossible to <em>index</em> string, only to slice it)</p>



<a name="189989008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/189989008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#189989008">(Mar 07 2020 at 22:28)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/text_unit/pull/2" target="_blank" title="https://github.com/rust-analyzer/text_unit/pull/2">Initial PR for text-size is up!</a></p>
<p>As I mentioned in the PR, I went pretty aggressive (and probably overboard) on allowing implicit "on-boarding" conversions, via taking <code>Into&lt;TextSize&gt;</code> for most functions. I expect to be vetoed on at least some of them.</p>
<p>The idea of the implicit conversions is to allow using <code>TextSize</code>/<code>TextRange</code> to be as painless as possible. <code>TextRange</code> is actually useful in being a <code>Copy</code> range and providing manipulation methods, but <code>TextSize</code> is "just" a newtype representing a "kind" of <code>u32</code>. The idea is that coersion points makes it so more API surface can adopt <code>TextSize</code> for correctness without regressing ergonomics of using integer literals and such.</p>



<a name="189997833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/189997833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#189997833">(Mar 08 2020 at 03:44)</a>:</h4>
<p>per <a href="https://github.com/rust-analyzer/text_unit/pull/2#discussion_r389319650" target="_blank" title="https://github.com/rust-analyzer/text_unit/pull/2#discussion_r389319650">https://github.com/rust-analyzer/text_unit/pull/2#discussion_r389319650</a>, I've removed all of the <code>Into&lt;TextSize&gt;</code> "on-boarding coercions". Reasoning: putting effort into allowing use of literals is "coding for the tests" a bit too much. The point of the crate is to separate text units from raw numbers, so having the split is a good thing.</p>



<a name="190005169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190005169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190005169">(Mar 08 2020 at 08:17)</a>:</h4>
<p>I guess the thing Rust lacks here is C++ish literals overloads...</p>



<a name="190023240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190023240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190023240">(Mar 08 2020 at 18:34)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> 's position that convinced me the most is that you shouldn't really be using literals of <code>TextSize</code>/<code>TextRange</code> outside of tests. And the API should work to serve the real code first, tests second.</p>



<a name="190023340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190023340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190023340">(Mar 08 2020 at 18:36)</a>:</h4>
<p>The most common literal to use would be <code>0</code>, and we can just provide <code>const TextSize::ZERO</code> and/or <code>const fn TextSize::zero()</code> for that case.</p>



<a name="190046560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190046560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190046560">(Mar 09 2020 at 07:42)</a>:</h4>
<p><span class="user-mention" data-user-id="132829">@Christopher Durham</span> what do you think about <a href="https://github.com/rust-analyzer/text_unit/pull/4" target="_blank" title="https://github.com/rust-analyzer/text_unit/pull/4">https://github.com/rust-analyzer/text_unit/pull/4</a>?</p>



<a name="190077548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190077548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190077548">(Mar 09 2020 at 14:57)</a>:</h4>
<p>I've forgotten the initial reason that I didn't pull over that requirement. I prefer <code>::new(start..end)</code> to <code>::new(start, end)</code> but that's just a minor syntax quibble.</p>



<a name="190077716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190077716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190077716">(Mar 09 2020 at 14:59)</a>:</h4>
<p>Unlike <code>ops::Range</code>, though, I've already noted a reverse range as immediately a logic error. So the well-formedness of the range is still assumable, just not for the fulfilment of <code>unsafe</code> requirements.</p>



<a name="190077996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190077996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190077996">(Mar 09 2020 at 15:01)</a>:</h4>
<p>Is there a use case where having a strict guarantee that the range is increasing is required? Or is it just a panic-sooner kind of thing for quicker catching of logic errors?</p>



<a name="190078163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190078163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190078163">(Mar 09 2020 at 15:02)</a>:</h4>
<p>It's for catching logic errors, yeah. And also for letting you not to think about this case as well .</p>



<a name="190078196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190078196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190078196">(Mar 09 2020 at 15:03)</a>:</h4>
<p>(also I have no idea what tbbs stands for)</p>



<a name="190078240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190078240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190078240">(Mar 09 2020 at 15:03)</a>:</h4>
<p>to be bikeshed</p>



<a name="190078676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190078676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190078676">(Mar 09 2020 at 15:07)</a>:</h4>
<p>So, if we are already at it, I also find <code>TextRange::new(lo..hi)</code> kind of nicer than <code>,</code>, and probably would even prefer to read/write just <code>TextRange(lo..hi)</code>. But isn't that too cute for the sake of code golf? <code>::new(lo, hi)</code> is boring, which is a major benefit</p>



<a name="190079016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079016">(Mar 09 2020 at 15:10)</a>:</h4>
<p>I think <code>::new(lo..hi)</code> is probably the best here</p>



<a name="190079052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079052">(Mar 09 2020 at 15:10)</a>:</h4>
<p>The reason I prefer it over <code>(lo, hi)</code> is that it makes the half-open semantics immediately clear</p>



<a name="190079068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079068">(Mar 09 2020 at 15:10)</a>:</h4>
<p>"this works like <code>ops::Range</code>"</p>



<a name="190079093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079093">(Mar 09 2020 at 15:11)</a>:</h4>
<p><a href="/user_uploads/4715/o3ZelQ8IZrRMyblEBiDQXyKi/image.png" target="_blank" title="image.png">image.png</a> and, tbh, <code>TextRange::from_to()</code></p>
<div class="message_inline_image"><a href="/user_uploads/4715/o3ZelQ8IZrRMyblEBiDQXyKi/image.png" target="_blank" title="image.png"><img src="/user_uploads/4715/o3ZelQ8IZrRMyblEBiDQXyKi/image.png"></a></div><p><a href="/user_uploads/4715/6RQZhxHa2IY3yooH2gVD956_/image.png" target="_blank" title="image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/6RQZhxHa2IY3yooH2gVD956_/image.png" target="_blank" title="image.png"><img src="/user_uploads/4715/6RQZhxHa2IY3yooH2gVD956_/image.png"></a></div>



<a name="190079122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079122">(Mar 09 2020 at 15:11)</a>:</h4>
<p><a href="/user_uploads/4715/GDDM0_LVNh4HvLYwNVKo5Q_V/image.png" target="_blank" title="image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/GDDM0_LVNh4HvLYwNVKo5Q_V/image.png" target="_blank" title="image.png"><img src="/user_uploads/4715/GDDM0_LVNh4HvLYwNVKo5Q_V/image.png"></a></div>



<a name="190079142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079142">(Mar 09 2020 at 15:11)</a>:</h4>
<p><code>,</code> formats better over several lines...</p>



<a name="190079342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079342">(Mar 09 2020 at 15:13)</a>:</h4>
<p>Yeah, that's the one reason to maybe prefer <code>,</code>.</p>



<a name="190079442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079442">(Mar 09 2020 at 15:14)</a>:</h4>
<p>Designing for a world with argument labels also is different from trying to work well without</p>



<a name="190079499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079499">(Mar 09 2020 at 15:14)</a>:</h4>
<p>Note that if it's the frist time you see <code>new(lo..hi)</code>, you'll probably go to check docs/source anyway, because "whyyy are we using <code>..</code> as an argument here? Is it an iterator"?</p>



<a name="190079686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079686">(Mar 09 2020 at 15:16)</a>:</h4>
<p>I wonder if</p>
<p><a href="/user_uploads/4715/o1xfWcwnA-Ax6tO6yxlopwOF/image.png" target="_blank" title="image.png">image.png</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/o1xfWcwnA-Ax6tO6yxlopwOF/image.png" target="_blank" title="image.png"><img src="/user_uploads/4715/o1xfWcwnA-Ax6tO6yxlopwOF/image.png"></a></div><p>is best? You get half-opennes and range semantics simply because there's a <code>Range</code>in the name</p>



<a name="190079733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079733">(Mar 09 2020 at 15:16)</a>:</h4>
<p>Anyway, should I merge that PR with invariant?</p>



<a name="190079774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079774">(Mar 09 2020 at 15:17)</a>:</h4>
<p>Maybe, but <code>Range::new(lo..hi)</code> I think is pretty clear. Or we can just ignore the "infallible" expectation of <code>From</code> and do <code>Range::from(lo..hi)</code> if that's clearer (with an inherent method)</p>



<a name="190079797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079797">(Mar 09 2020 at 15:17)</a>:</h4>
<p>But I'm warming up to the "fake tuple struct," actually</p>



<a name="190079911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079911">(Mar 09 2020 at 15:18)</a>:</h4>
<p>I'd say rebase it to add the restriction to the "tuple struct constructor" then merge it</p>



<a name="190079939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190079939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190079939">(Mar 09 2020 at 15:18)</a>:</h4>
<p>(internal const construction can just fall back to <code>{ start, end }</code>)</p>



<a name="190080061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080061">(Mar 09 2020 at 15:19)</a>:</h4>
<p>It's sad to see <code>From</code> go but I think it's for the better</p>



<a name="190080177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080177">(Mar 09 2020 at 15:20)</a>:</h4>
<p>tbh, I don't think I've ever wanted From for ranges</p>



<a name="190080204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080204">(Mar 09 2020 at 15:21)</a>:</h4>
<p>I wanted to do <code>text[text_size..]</code>, but that's another story</p>



<a name="190080215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080215">(Mar 09 2020 at 15:21)</a>:</h4>
<p>Yeah, it's more a theoretical sadness than a practical one</p>



<a name="190080217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080217">(Mar 09 2020 at 15:21)</a>:</h4>
<p>And since we're "fake tuple struct"ing <code>TextRange</code> we should probably do it for <code>TextSize</code> as well.</p>



<a name="190080310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080310">(Mar 09 2020 at 15:22)</a>:</h4>
<p>Though to be clear: not marking the constructor as <code>const</code> is a difference from real tuple structs (along with the lack of pattern matching through them).</p>



<a name="190080355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080355">(Mar 09 2020 at 15:22)</a>:</h4>
<p>We can make them const tho</p>



<a name="190080380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080380">(Mar 09 2020 at 15:22)</a>:</h4>
<p><code>[()][(start &gt; end) as usize]</code></p>



<a name="190080423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080423">(Mar 09 2020 at 15:22)</a>:</h4>
<p>Oh no const assert hacks‽ Yes please</p>



<a name="190080502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080502">(Mar 09 2020 at 15:23)</a>:</h4>
<p>Though I'd prefer to just put an assert there, and then wait until it is const :D</p>



<a name="190080648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080648">(Mar 09 2020 at 15:24)</a>:</h4>
<p>Please give me <code>const assert!</code> lang team</p>



<a name="190080709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080709">(Mar 09 2020 at 15:25)</a>:</h4>
<p>If adding <code>static_assertions</code> as a dep is ok, they have <code>const_assert!</code> to wrap up the trickery</p>



<a name="190080752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080752">(Mar 09 2020 at 15:25)</a>:</h4>
<p>(and it is a leaf dependency)</p>



<a name="190080840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190080840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190080840">(Mar 09 2020 at 15:26)</a>:</h4>
<p>Wait nvm I'm pretty sure <code>const_assert!</code> only works on constants, not just in a const context</p>



<a name="190081470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190081470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190081470">(Mar 09 2020 at 15:31)</a>:</h4>
<p>Pushed, but I am having second thoughs about fake tuple for <code>TextSize</code></p>



<a name="190081505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190081505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190081505">(Mar 09 2020 at 15:32)</a>:</h4>
<p><code>TextRanges</code> you do create from various offset mansually</p>



<a name="190081551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190081551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190081551">(Mar 09 2020 at 15:32)</a>:</h4>
<p><code>TextSize</code>, however, you should really crate with <code>of</code></p>



<a name="190081618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190081618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190081618">(Mar 09 2020 at 15:33)</a>:</h4>
<p>Maybe I am being to pedantic here, but I'd really love to see <code>TextSize::of(":")</code>, rather than <code>TextSize(1)</code>, and not having tuple ctor helps with that</p>



<a name="190081651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190081651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190081651">(Mar 09 2020 at 15:33)</a>:</h4>
<p>Ie, you can crate a range from two sizes, but the only "officail" way to create a size would be to measure something</p>



<a name="190083114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190083114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190083114">(Mar 09 2020 at 15:45)</a>:</h4>
<p>That makes sense</p>



<a name="190083369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190083369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190083369">(Mar 09 2020 at 15:47)</a>:</h4>
<p>Ok, merged that PR</p>



<a name="190083843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190083843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wojciech Polak <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190083843">(Mar 09 2020 at 15:51)</a>:</h4>
<p>This const assert hack made my day. Thanks :)</p>



<a name="190084018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190084018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190084018">(Mar 09 2020 at 15:52)</a>:</h4>
<p><span class="user-mention" data-user-id="214828">@Wojciech Polak</span> <a href="https://github.com/rust-analyzer/smol_str/commit/c7ce079a24cdd67eaf972f070874c6be7c166082" target="_blank" title="https://github.com/rust-analyzer/smol_str/commit/c7ce079a24cdd67eaf972f070874c6be7c166082">https://github.com/rust-analyzer/smol_str/commit/c7ce079a24cdd67eaf972f070874c6be7c166082</a> :D</p>



<a name="190086591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190086591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190086591">(Mar 09 2020 at 16:13)</a>:</h4>
<p>We should make a crate out of this</p>



<a name="190086832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190086832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190086832">(Mar 09 2020 at 16:14)</a>:</h4>
<p>Oh, wait it already exists</p>



<a name="190097524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190097524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190097524">(Mar 09 2020 at 17:50)</a>:</h4>
<p>Specifically, while I'm pretty sure <a href="https://docs.rs/static_assertions/1.1.0/static_assertions/macro.const_assert.html" target="_blank" title="https://docs.rs/static_assertions/1.1.0/static_assertions/macro.const_assert.html"><code>static_assertions::const_assert</code></a> only works for statically-known consts, <a href="https://docs.rs/const_fn_assert/0.1.2/const_fn_assert/macro.cfn_assert.html" target="_blank" title="https://docs.rs/const_fn_assert/0.1.2/const_fn_assert/macro.cfn_assert.html"><code>const_fn_assert::cfn_assert</code></a> works for "const-time" asserts with a not completely horrible const-time error (but understandably bad runtime error).</p>



<a name="190278214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190278214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wojciech Polak <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190278214">(Mar 11 2020 at 13:04)</a>:</h4>
<p>I really like these changes, maybe Ill use this <code>text-size 0.99</code> crate in my next "Parser in Rust" article :)</p>



<a name="190463460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190463460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190463460">(Mar 13 2020 at 01:40)</a>:</h4>
<p>Just keep in mind that it's not quite stable yet, as we argue out the remaining details :)</p>



<a name="190479912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/190479912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wojciech Polak <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#190479912">(Mar 13 2020 at 08:14)</a>:</h4>
<p>I noticed ;)</p>



<a name="191164674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191164674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191164674">(Mar 19 2020 at 19:36)</a>:</h4>
<p>I think we're converging on what we want to publish as v0.99, so I published v0.99.0-dev.2 (and also invited matklad to own), so that I can make experimental patches for rowan and rust-analyzer.</p>



<a name="191313105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191313105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191313105">(Mar 20 2020 at 22:59)</a>:</h4>
<p>Here's a couple papercuts I found with text-size in porting rowan to use it:</p>
<ul>
<li>Given <code>s: &amp;SmolStr</code>, you can call <code>TextUnit::of_str(s)</code>, but not <code>TextSize::of(s)</code>; requiring <code>TextSize::of(&amp;**s)</code>. This is solvable in text-size via a blanket recursive impl.<ul>
<li>Simpler: <code>impl&lt;D&gt; TextSized for &amp;'_ D where D: Deref&lt;Target = str&gt;</code></li>
<li>More complete: <code>impl&lt;D&gt; TextSized for &amp;'_ D where D: Deref, for&lt;'a&gt; &amp;'a D::Target: TextSized</code></li>
</ul>
</li>
<li><code>self.range.contains_range(range)</code><ul>
<li><code>.contains_range(range)</code> is disturbingly common.</li>
</ul>
</li>
<li><code>SyntaxTextRange</code> should probably be replaced by <code>RangeBounds&lt;TextSize&gt;</code>, but also brings up an interesting change:<ul>
<li><code>range.start()</code> for <code>range: &amp;TextRange</code> now prefers <code>SyntaxTextRange::start</code> over <code>TextRange::start</code> due to the way method resolution works.</li>
</ul>
</li>
<li><code>TextRange::empty(offset)</code> should probably be <code>TextRange::empty_at(offset)</code> and/or <code>TextRange::empty() + offset</code> (<code>TextRange::zero() + offset</code>?)</li>
</ul>



<a name="191313130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191313130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191313130">(Mar 20 2020 at 22:59)</a>:</h4>
<p>Here's the rowan patch: <a href="https://github.com/CAD97/rowan/pull/3" target="_blank" title="https://github.com/CAD97/rowan/pull/3">https://github.com/CAD97/rowan/pull/3</a></p>



<a name="191315360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191315360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191315360">(Mar 20 2020 at 23:33)</a>:</h4>
<p>And here's <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=008b5e0c2edd332b34b3efa42ce2a40a" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=008b5e0c2edd332b34b3efa42ce2a40a">a playground showing off the deref-coersion style(?) <code>TextSized</code> impls</a></p>



<a name="191316361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191316361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191316361">(Mar 20 2020 at 23:48)</a>:</h4>
<p>I think we should add only the first blanket impls</p>



<a name="191316383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191316383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191316383">(Mar 20 2020 at 23:48)</a>:</h4>
<p>range.conains_range(range) is funny, but is strictly better than the reversed is_subrange</p>



<a name="191316519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191316519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191316519">(Mar 20 2020 at 23:51)</a>:</h4>
<p>Not sure about the last one</p>



<a name="191316545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191316545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191316545">(Mar 20 2020 at 23:51)</a>:</h4>
<p>Seems like empty with argument is the right thing, as there are many empty ranges</p>



<a name="191316566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191316566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191316566">(Mar 20 2020 at 23:51)</a>:</h4>
<p><code>empty_at</code> probably is clearer for that case, though</p>



<a name="191316643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191316643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191316643">(Mar 20 2020 at 23:52)</a>:</h4>
<p>It's a bit of "argument hint" bias to have <code>TextRange::empty(offset: size)</code>, but <code>TextRange::empty_at(offset: size)</code> serves those both with and without imho</p>



<a name="191316693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191316693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191316693">(Mar 20 2020 at 23:53)</a>:</h4>
<p>Not sold: like you see there is an argument for <code>empty</code>, and it <em>could</em> only mean one single ting</p>



<a name="191316708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191316708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191316708">(Mar 20 2020 at 23:54)</a>:</h4>
<p>you don't need to know its name to guess what does it mean</p>



<a name="191316838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191316838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191316838">(Mar 20 2020 at 23:55)</a>:</h4>
<p>The one counterargument is that <code>TextRange::empty(TextSize::zero())</code> is _also_ common<br>
and I'd guess at it being a decent chunk of <code>::empty</code> calls</p>



<a name="191316895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191316895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191316895">(Mar 20 2020 at 23:56)</a>:</h4>
<p>So that would be better served by having <code>::empty()</code>, rather than relying on <code>::default()</code> being <code>::empty()</code></p>



<a name="191316906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191316906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191316906">(Mar 20 2020 at 23:56)</a>:</h4>
<p>... which we don't even provide <code>Default</code> currently</p>



<a name="191333574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191333574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191333574">(Mar 21 2020 at 07:45)</a>:</h4>
<p>But <code>::empty()</code> does not make sense: there are <code>u32::max</code> empty text ranges. Providing <code>default</code> seems like a good idea to me though!</p>



<a name="191410894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191410894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191410894">(Mar 22 2020 at 19:02)</a>:</h4>
<blockquote>
<p>there are <code>u32::MAX</code> empty text ranges</p>
</blockquote>
<p>This is what convinced me.</p>



<a name="191412977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191412977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191412977">(Mar 22 2020 at 19:49)</a>:</h4>
<p>This text range thing is just a vector of two coordinates that has 3 degenerate cases: <code>null_vector(0, 0)</code>; <code>unbiased(0, p)</code>; <code>empty(p, 0)</code></p>



<a name="191413343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191413343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191413343">(Mar 22 2020 at 19:59)</a>:</h4>
<p>I also wonder wouldn't it make sense to <code>std::ops::Range*&lt;TextUnit&gt;</code> instead of <code>TextRange</code> just for the additional syntax sugar?</p>



<a name="191414849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191414849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191414849">(Mar 22 2020 at 20:35)</a>:</h4>
<p>Three main problems with that:</p>
<ul>
<li><code>ops::Range</code> is not <code>Copy</code>, and having a <code>Copy</code> range is a nice bonus for using a crate like this,</li>
<li><code>ops::Range</code> does not guarantee a nondecreasing "forwards" range, which matklad is a fan of having as a guarantee to catch errors early, and</li>
<li>there is currently no way to index with <code>ops::Range&lt;MyType&gt;</code> <a href="https://github.com/rust-lang/rust/issues/35729#issuecomment-598777102" target="_blank" title="https://github.com/rust-lang/rust/issues/35729#issuecomment-598777102">because of <code>SliceIndex</code></a>.</li>
</ul>



<a name="191416593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/text-size/near/191416593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/text-size.html#191416593">(Mar 22 2020 at 21:15)</a>:</h4>
<p>Hmm, I wish the following worked:</p>
<div class="codehilite"><pre><span></span><span class="k">impl</span><span class="w"> </span><span class="nb">Copy</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">std</span>::<span class="n">ops</span>::<span class="n">Range</span><span class="o">&lt;</span><span class="n">TextUnit</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div>


<p>but it fails due to coherence rules...<br>
Anyway, yeah that's reasonable</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>